<?php
    /*  If connection fails, must be silent as this script is loaded externally.
     *  error catching is handled by the requestor.
     */
    require_once("../includes/functions.php");
    $q = @mysql_real_escape_string(sanitise_search_term($_GET['term']));

    $query = @mysql_query("SELECT `terms` FROM `searches` WHERE `terms` LIKE '{$q}%' ORDER BY `frequency` DESC LIMIT 8") or die(mysql_error());
    $result = array();
    while ($temp=@mysql_fetch_assoc($query)) {
        array_push($result,array("id"=>$temp['terms'],"value"=>$temp['terms']));
    }
    $res = array_to_json($result);
    echo $res;
    @mysql_close();
?>